package com.zyx.javademo.stream;


import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

/**
 * @author Yaxi.Zhang
 * @since 2021/5/28 10:53
 * desc: 将Iterable接口对象转化为流
 */
public class IterableToStreamDemo {
    public static void main(String[] args) {
        Iterable<Integer> iterable = Arrays.asList(1, 2, 3, 4, 5);
        // Iterable -> Spliterators -> Stream -> List
        // 由于Iterable接口具有spliterator()方法，因此更容易将其转换为Stream 。
        List<Integer> result = StreamSupport.stream(
                iterable.spliterator(), false)
                .map(x -> x * 10)
                .collect(Collectors.toList());

        result.forEach(System.out::println);
        System.out.println(result.getClass());
    }
}
